﻿using GetData;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace jutehui.GetData
{
    public static class MallsEnumClass
    {
        public enum UrlType
        {
            //苏宁 &utm_content
            [Description("http://sucs.suning.com/visitor.htm?userId=5360&webSiteId=0&adInfoId=0&adBookId=0&channel=24&vistURL=")]
            suning,//= "suning",

            //亚马逊
            [Description("?")]
            amazon,// = "amazon",

            //一号店
            [Description("?tracker_u=108881507")]
            yhd,// = "yhd",

            //京东
            [Description("")]
            jd,//= "item.jd",

            //建1网
            [Description("&t=")]
            yiqifa,// = "www.j1.com",

            //天猫
            [Description("")]
            tmall,// = "detail.tmall",

            //糯米
            [Description("&t=")]
            nuomi,// = "nuomi",

            //优购
            [Description("utm_source=YgSJlegao")]
            yougou,// = "yougou",

            //莎莎
            [Description("&tu=")]
            sasa,//= "sasa",

            //易迅
            [Description("&tu=")]
            yixun,// = "yixun",

            //国美 &utm_content
            [Description("&to=")]
            gome,// = "guomei"

            [Description("&tu=")]
            muyingzhijia,

            [Description("?")]
            okbuy,

            //当当
            [Description("?unionid=p-327780m")]
            dangdang,

            //尚装
            [Description("&t=")]
            showjoy,

            //中粮
            [Description("&tu=")]
            womai,

            //新蛋
            [Description("?")]
            newegg,

            //唯品会
            [Description("?")]
            vip,

            //1号药网
            [Description("?tracker_u=2015050501")]
            yiyao,
            //有货网
            [Description("")]
            yohobuy,
            //淘宝
            [Description("")]
            taobao,
            //飞牛网
            feiniu,
            //速普
            supuy,
            //可得眼镜
            keede,
            //大普
            dapu,
            //ashford
            ashford,
        }
        private static int numRunGetEndUrl = 0;
        private static readonly object locker = new object();
        //   private static WebBrowserWaiter.WebBrowserWaiter waiter = new WebBrowserWaiter.WebBrowserWaiter();
        // private static string locker = "";
        public enum NavigationType
        {
            精选 = 1,
            海淘 = 2,

        }
        /// <summary>
        /// 获取天猫最终跳转的页面
        /// </summary>
        /// <param name="originUrl"></param>
        /// <returns></returns>
        private static string GetEndUrl(string originUrl)
        {
            try
            {
                return originUrl;
                //lock (locker)
                //{
                //    string EndUrl = "";

                //    using (var waiter = new WebBrowserWaiter.WebBrowserWaiter())
                //    {

                //        waiter.Await(TimeSpan.FromSeconds(5), wb =>
                //        {
                //            wb.Navigate(originUrl);
                //            wb.AllowNavigation = false;
                //            wb.ScriptErrorsSuppressed = true;
                //        }, wb =>
                //        {
                //            wb.AllowNavigation = false;
                //            wb.ScriptErrorsSuppressed = true;
                //            wb.Navigate(originUrl);

                //            if (wb.Document != null)
                //            {
                //                /* var script = "function getHref(){return hrl;}";
                //                 wb.Document.InvokeScript("execScript", new Object[] {script, "JavaScript"});
                //                 var jdUrl = wb.Document.InvokeScript("getHref", new object[] {"hello world"}).ToString();
                //                 endUrl = HttpHelper.GetRedirctUrl(jdUrl, new CookieContainer());*/
                //                if (wb.Document.Url != null)
                //                {
                //                    EndUrl = wb.Document.Url.ToString();
                //                }

                //            }
                //            wb.Dispose();
                //        });

                //    }

                //    return EndUrl;
                //}

            }
            catch (Exception ex)
            {
                CustomMethod.WriteLog("GetEndUrl:" + ex.Message.ToString());
                return "";
            }
        }

        /// <summary> 
        /// 根据url获取最终url 和推广url
        /// </summary>
        /// <param name="url"></param>
        /// <param name="productUrl"></param>
        /// <returns></returns>
        public static string GetSourceUrl(string url, ref string productUrl)
        {
            string trueUrl = System.Web.HttpUtility.UrlDecode(url, System.Text.Encoding.UTF8);
            string tmchanel = "&pid=mm_45871999_39404541_147374618";
            //获取天猫跳转最终页面
            if (trueUrl.Contains("taobao"))
            {
                int startIndex = trueUrl.LastIndexOf("http");
                trueUrl = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (trueUrl.Contains("taobao"))
                {
                    trueUrl = GetEndUrl(trueUrl);
                    url = trueUrl;
                }
                if (trueUrl.Contains("ai.taobao"))
                {
                    string htmltext = CustomMethod.GetHtmlByHttpHelper(trueUrl);
                    string titlRegex = @"<h3 class=""item-title"">[\s\S]*?</div>";
                    var content = CustomMethod.GetInfoByRegex(titlRegex, htmltext, 0);
                    if (content.Count > 0)
                    {
                        var linkList = CustomMethod.GetInfoFroma(content[0]);
                        if (linkList.Count > 1)
                        {
                            string currentUrl = linkList[0];

                            trueUrl = GetEndUrl(currentUrl);

                            url = trueUrl;
                        }
                        else
                        {
                            productUrl = "";
                            return "";
                        }
                    }
                    else
                    {
                        trueUrl = GetEndUrl(trueUrl);
                        url = trueUrl;
                    }
                    //string dd = Parse(trueUrl);
                }

            }

            //一次编码后还有utf8内容
            if (trueUrl.Contains("%") && !trueUrl.Contains("ai.taobao"))
            {
                trueUrl = System.Web.HttpUtility.UrlDecode(trueUrl, System.Text.Encoding.UTF8);
            }

            if (trueUrl.Contains("?purl="))
            {
                int startIndex = trueUrl.IndexOf("?purl=");
                trueUrl = trueUrl.Substring(startIndex + 6, trueUrl.Length - startIndex - 6);
                int startIndexOfUrl = url.IndexOf("?purl=");
                url = url.Substring(startIndexOfUrl + 6, url.Length - startIndexOfUrl - 6);
            }
            string sourceUrl = "";
            if (url.Contains(UrlType.yhd.ToString()))
            {
                //http://item.yhd.com/item/54586972?tracker_u=108881507
                string Chanel = "https://0410c.duomai.com/track.php?site_id=227958&aid=516&euid=maytao&t=";// "tracker_u=108881507";
                string tag = "";
                int startIndex = trueUrl.LastIndexOf("http:");
                trueUrl = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);

                if (trueUrl.Contains("http://t.yhd.com/"))
                {
                    trueUrl = trueUrl.Replace("http://t.yhd.com/", "http://t.m.yhd.com/");
                }
                else if (trueUrl.Contains("http://item.yhd.com/"))
                {
                    trueUrl = trueUrl.Replace("http://item.yhd.com/", "http://item.m.yhd.com/");
                }
                if (trueUrl.Contains("?"))
                {
                    var list = trueUrl.Split('?').ToList();
                    productUrl = list[0]; 
                    sourceUrl = Chanel + System.Web.HttpUtility.UrlEncode(productUrl, System.Text.Encoding.UTF8); 
                    return sourceUrl;
                }
                else if (trueUrl.Contains("&"))
                {
                    var list = trueUrl.Split('&').ToList();
                    productUrl = list[0];
                   
                    if (!sourceUrl.Contains(tag))
                    {
                        sourceUrl = Chanel + System.Web.HttpUtility.UrlEncode(productUrl, System.Text.Encoding.UTF8); 
                    }
                    else
                    {
                        sourceUrl = Chanel + System.Web.HttpUtility.UrlEncode(productUrl, System.Text.Encoding.UTF8); 
                    }

                    return sourceUrl;
                }
                productUrl = trueUrl;
                sourceUrl = Chanel + System.Web.HttpUtility.UrlEncode(productUrl, System.Text.Encoding.UTF8);

                return sourceUrl;
            }
            #region  一起发
            else if (trueUrl.Contains("sfbest.com"))
            {
                string channel = "http://p.yiqifa.com/n?k=2mLErnDS6n3FrI6H2mLErBPdYngSYQLq6lzs6QLFWljqWNBHWNRsWnw7rI6HkQLErJDe6NjFWn3FrIW-&t=";// "http://c.duomai.com/track.php?site_id=193113&aid=1227&euid=&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else if (urlStr.Contains("&"))
                {
                    sourceUrl = urlStr.Split('&').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                if (!sourceUrl.Contains("activity"))
                {
                    productUrl = sourceUrl.Replace("www", "m");
                    sourceUrl = channel + productUrl;
                }
                else
                {
                    productUrl = sourceUrl;

                }
                //  sourceUrl = GetUrlByChannel(channel, productUrl);


                return productUrl;
            }
            else if (trueUrl.Contains("muyingzhijia"))
            {
                //http://item.muyingzhijia.com/151825.html
                //http://www.muyingzhijia.com/Shopping/ActivityPage.aspx
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                if (sourceUrl.Contains("item.muyingzhijia"))
                {
                    string channel = "http://c.duomai.com/track.php?site_id=193113&aid=897&euid=&t=";

                    string Currenturl = "http://m.muyingzhijia.com/Goods";

                    int endIndex = sourceUrl.LastIndexOf("/");
                    string lastUtlPart = sourceUrl.Substring(endIndex, sourceUrl.Length - endIndex);

                    productUrl = Currenturl + lastUtlPart;
                    // sourceUrl = GetUrlByChannel(channel, productUrl);
                    sourceUrl = productUrl;
                }
                else
                {
                    productUrl = sourceUrl;
                }
                return sourceUrl;
            }
            else if (trueUrl.Contains("j1.com"))
            {
                string channel = "http://c.duomai.com/track.php?site_id=193113&aid=996&euid=&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else if (urlStr.Contains("&"))
                {
                    sourceUrl = urlStr.Split('&').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                productUrl = sourceUrl.Replace("www", "m");

                //sourceUrl = GetUrlByChannel(channel, productUrl);
                return productUrl;
            }
            else if (trueUrl.Contains("wangfujing.com"))
            {
                //http://p.yiqifa.com/jc?fit=b&e=gdr&c=7034&i=26662&w=658154&l=0&t=http://www.wangfujing.com/item/P000000000010015556
                string channel = "http://c.duomai.com/track.php?site_id=193113&aid=924&euid=&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                productUrl = trueUrl.Substring(startIndex, trueUrl.Length - startIndex).Replace("www", "m");
                //  sourceUrl = GetUrlByChannel(channel, productUrl);
                return productUrl;
            }
            else if (trueUrl.Contains("sasa"))
            {
                //http://www.sasa.com/seckill-12271.html
                string channel = "http://c.duomai.com/track.php?site_id=193113&aid=819&euid=&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else if (urlStr.Contains("&"))
                {
                    sourceUrl = urlStr.Split('&').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                productUrl = sourceUrl.Replace("http://www.sasa.com/", "http://www.sasa.com/wap/");
                //  sourceUrl = GetUrlByChannel(channel, productUrl);
                return productUrl;
            }
            else if (trueUrl.Contains("yintai.com"))
            {
                //http://item.yintai.com/20-242-1159C.html
                string channel = "http://c.duomai.com/track.php?site_id=193113&aid=432&euid=&t=";

                string murl = "http://m.yintai.com/Sales/ProductDetail?itemCode=";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                if (sourceUrl.Contains("item.yintai.com"))
                {
                    int mstartindex = sourceUrl.IndexOf("com/");
                    int mendindex = sourceUrl.IndexOf(".html");
                    var pid = sourceUrl.Substring(mstartindex + 4, mendindex - mstartindex - 4);
                    sourceUrl = murl + pid.Replace("C", "");
                }
                else
                {
                    sourceUrl = sourceUrl.Replace("www", "m");
                }
                productUrl = sourceUrl;
                //sourceUrl = GetUrlByChannel(channel, productUrl);
                return sourceUrl;
            }
            else if (trueUrl.Contains("www.mia.com"))
            {
                string channel = "http://c.duomai.com/track.php?site_id=193113&aid=1770&euid=&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                string currentUrl = trueUrl.Substring(startIndex, trueUrl.Length - startIndex).Split('&').ToList()[0].Replace("www", "m");
                productUrl = currentUrl;
                // sourceUrl = GetUrlByChannel(channel, productUrl);
                return productUrl;
            }
            else if (trueUrl.Contains("vsigo.cn"))
            {
                string channel = "http://c.duomai.com/track.php?site_id=193113&aid=1548&euid=&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                productUrl = sourceUrl.Replace("www", "m");
                // sourceUrl = GetUrlByChannel(channel, productUrl);
                return productUrl;
            }

            else if (trueUrl.Contains("keede.com"))
            {
                string channel = "http://c.duomai.com/track.php?site_id=193113&aid=1236&euid=&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                productUrl = sourceUrl.Replace("www", "m");
                //sourceUrl = GetUrlByChannel(channel, productUrl);
                return productUrl;
            }
            else if (trueUrl.Contains("metao.com"))
            {
                string currenturl = "http://m.metao.com/wap/";
                string channel = "http://c.duomai.com/track.php?site_id=193113&aid=2175&euid=&t=";
                int startIndex = trueUrl.LastIndexOf("products/");
                productUrl = currenturl + trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                // sourceUrl = GetUrlByChannel(channel, productUrl);
                return productUrl;
            }
            else if (trueUrl.Contains("zhiwo"))
            {
                string channel = "http://p.yiqifa.com/n?k=2mLErnWe6E3OrI6H2mLErtBygJysRmLq6lWe1ZLFWljqWNBH6l3mWnUH2mqerI6HWNX9MnzF35gH2L--&t="; //"http://c.duomai.com/track.php?site_id=193113&aid=804&euid=&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr.Split('&').ToList()[0]; ;
                }
                string urlzhiwo = "http://m.zhiwo.com/group/view?goods_id=";
                //正则匹配数字
                string strRegex = @"/[1-9]\d*|0$";
                var numContent = CustomMethod.GetInfoByRegex(strRegex, sourceUrl, 0);

                productUrl = urlzhiwo + numContent[0].Replace("/", "");

                // sourceUrl = GetUrlByChannel(channel, productUrl);
                sourceUrl = channel + productUrl;
                return productUrl;
            }
            else if (url.Contains("tootoo"))
            {
                string channel = "http://c.duomai.com/track.php?site_id=193113&aid=1761&euid=&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("&"))
                {
                    sourceUrl = urlStr.Split('&').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                productUrl = sourceUrl.Replace("www", "m");
                // sourceUrl = GetUrlByChannel(channel, productUrl);
                return productUrl;
            }
            else if (url.Contains(UrlType.yohobuy.ToString()))
            {
                string channel = "http://p.yiqifa.com/n?k=2mLErnDS6E27rI6H2mLErI6HWNzL6nyH1nWLWNtqrnte6N2ertPbMmjL6ZqerI6HMNWlMnKqMJ6H2L--&t=";// "http://c.duomai.com/track.php?site_id=193113&aid=1725&euid=&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                int endIndex = trueUrl.LastIndexOf(".html");
                string currentUrl = trueUrl.Substring(startIndex, endIndex - startIndex) + ".html".Replace("item", "m");
                productUrl = currentUrl;

                //sourceUrl = GetUrlByChannel(channel, productUrl);
                sourceUrl = channel + productUrl;
                //var list = url.Split('=').ToList();
                //var itemlist = trueUrl.Split('?').ToList();
                //if (itemlist != null && itemlist.Count > 0)
                //{
                //    productUrl = itemlist[0].Replace("www","m");
                //    sourceUrl = itemlist[0];

                //}

                return sourceUrl;

            }
            //丰趣海淘
            else if (trueUrl.Contains("fengqu.com"))
            {
                //http://www.fengqu.com/detail/6132.html?_src=tpy  http%3A%2F%2Fm.fengqu.com%2F
                string channel = "http://c.duomai.com/track.php?site_id=193113&aid=2307&euid=&t=";
                var murl = trueUrl.Split('?').ToList()[0].Replace("www", "m");
                string encodUrl = System.Web.HttpUtility.UrlEncode(murl, System.Text.Encoding.UTF8);
                productUrl = murl;
                //sourceUrl = GetUrlByChannel(channel, productUrl);
                return productUrl;
            }
            #endregion
            else if (trueUrl.Contains("xiji.com"))
            {
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                productUrl = sourceUrl.Replace("www", "m");
                sourceUrl = sourceUrl.Replace("www", "m");
                return sourceUrl;
            }
            else if (url.Contains("suning"))
            { 
                string Chanel = "https://0410c.duomai.com/track.php?site_id=227958&aid=84&euid=maytao&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                int endIndex = trueUrl.LastIndexOf(".htm");

                if (endIndex > startIndex)
                {
                    //http://sucs.suning.com/visitor.htm?userId=5360&webSiteId=0&adInfoId=0&adBookId=0&channel=24&vistURL=http://product.suning.com/0000000000/125374476.html
                    sourceUrl = trueUrl.Substring(startIndex, endIndex - startIndex) + ".html";
                    string lastUrl = sourceUrl.Replace("product.suning.com", "m.suning.com/product");
                    productUrl = lastUrl;

                    sourceUrl = Chanel + System.Web.HttpUtility.UrlEncode(lastUrl, System.Text.Encoding.UTF8); ;
                }

                return sourceUrl;

            }
            else if (url.Contains("6pm.com"))
            {
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("&"))
                {
                    sourceUrl = urlStr.Split('&').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                productUrl = sourceUrl;
                return sourceUrl;
            }
            else if (url.Contains("dangdang.com"))
            {
                //http://product.dangdang.com/product.aspx?product_id=60604678
                string Chanel = "http://union.dangdang.com/transfer.php?sys_id=1&ad_type=10&from=P-336541m&backurl=";
                string tag = "";
                int startIndex = trueUrl.LastIndexOf("http");
                string secondUrl = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (secondUrl.Contains("product.dangdang.com"))
                {
                    secondUrl = secondUrl.Replace("product.dangdang.com", "product.m.dangdang.com");
                }
                if (secondUrl.Contains(".htm"))
                {
                    if (secondUrl.Contains("?"))
                    {
                        var list = secondUrl.Split('?').ToList();
                        sourceUrl = Chanel + System.Web.HttpUtility.UrlEncode(list[0], System.Text.Encoding.UTF8);
                        productUrl = list[0];
                        return sourceUrl;
                    }
                    else if (secondUrl.Contains("&"))
                    {
                        var list = secondUrl.Split('&').ToList();
                        if (!list[0].Contains(tag))
                        {
                            sourceUrl = Chanel + System.Web.HttpUtility.UrlEncode(list[0], System.Text.Encoding.UTF8); ;
                        }
                        else
                        {
                            sourceUrl = Chanel + System.Web.HttpUtility.UrlEncode(list[0], System.Text.Encoding.UTF8); ;
                        }
                        productUrl = list[0];
                        return sourceUrl;
                    }
                }


                else
                {
                    productUrl = secondUrl.Split('&').ToList()[0];
                    sourceUrl = Chanel + System.Web.HttpUtility.UrlEncode(productUrl, System.Text.Encoding.UTF8);
                    // sourceUrl = secondUrl;
                    return sourceUrl;
                }
                sourceUrl = Chanel + System.Web.HttpUtility.UrlEncode(secondUrl, System.Text.Encoding.UTF8); 
                productUrl = secondUrl;

                return sourceUrl;
            }
            else if (url.Contains("yougou"))
            {
                //http://www.yougou.com/c-hushpuppies/sku-h1i23cm3-99926334.shtml?utm_source=YgSJlegao
                int startIndex = trueUrl.LastIndexOf("http");
                int endIndex = trueUrl.LastIndexOf(".shtml");
                if (endIndex > startIndex)
                {
                    trueUrl = trueUrl.Substring(startIndex, endIndex - startIndex);
                    sourceUrl = trueUrl.Replace("http://www.yougou.com/", "http://m.yougou.com/touch/");
                    string Chanel = "?utm_source=YgSJlegao";

                    productUrl = sourceUrl;
                    sourceUrl = sourceUrl + Chanel;
                }
                else
                {
                    int pcendIndex = trueUrl.LastIndexOf(".html");
                    trueUrl = trueUrl.Substring(startIndex, pcendIndex - startIndex) + ".html";
                    sourceUrl = trueUrl;
                    productUrl = sourceUrl;
                }
                return sourceUrl;
            }
            else if (url.Contains("111.com.cn")) //壹药网
            {
                string Chanel = "?tracker_u=2015050501 ";
                int startIndex = trueUrl.LastIndexOf("http");
                string lastUrl = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                lastUrl = lastUrl.Replace("www.111", "m.111");
                var list = lastUrl.Split('?').ToList();
                trueUrl = list[0];
                sourceUrl = trueUrl + Chanel;
                productUrl = trueUrl;

                return sourceUrl;
            }
            else if (trueUrl.Contains("jd.com"))
            {
                //http://c.duomai.com/track.php?t=http://wqs.jd.com/event/brand/hlqzrn_/index.shtml&aid=61&site_id=94527&euid=n1769696
                //http://p.yiqifa.com/n?k=psMgYmAWrI6HWN3LrI6H2mLErI6HWEK7rnDS1nzF1ZLO6nUH2mqerI6H35KLWNj7WNUH2L--&e=yqf&t=http://item.jd.com/10104273578.html
                if (trueUrl.IndexOf("p.yiqifa") > 0)
                {
                    int endIndex = trueUrl.LastIndexOf("=");

                    trueUrl = trueUrl.Substring(endIndex + 1, trueUrl.Length - endIndex - 1);
                }

                //当静态变量为空时，读取xml数据
                if (ParamsClass.jdmodel == null)
                {
                    ParamsClass.jdmodel = new jdCongfigModel();
                    xmlOperate xmlManager = new xmlOperate();
                    ParamsClass.jdmodel = xmlManager.GetJDModelByXML();
                }

                //http://c.duomai.com/track.php?t=http://www.jd.com/&aid=61&site_id=94527&euid=n1667025 
                if (trueUrl.Contains("www.jd.com"))
                {
                    sourceUrl = "http://m.jd.com";
                    productUrl = sourceUrl;
                    return sourceUrl;
                }
                if (trueUrl.Contains("sale.jd.com") || trueUrl.Contains("jmall.jd.com") || trueUrl.Contains("jmall.jd.com"))
                {
                    //http://c.duomai.com/track.php?t=http://sale.jd.com/act/CnoOeBZqVUjvlp.html/&aid=61&site_id=94527&euid=n1664993
                    int startIndex = trueUrl.LastIndexOf("http");
                    int endIndex = trueUrl.IndexOf(".html");
                    sourceUrl = trueUrl.Substring(startIndex, endIndex - startIndex) + ".html";
                    productUrl = sourceUrl;

                    return sourceUrl;
                }
                if (trueUrl.Contains("item.jd.com"))
                {


                    int startIndex = trueUrl.LastIndexOf("jd.com/");
                    int lastIndex = trueUrl.IndexOf(".html");
                    if (lastIndex > startIndex)
                    {
                        sourceUrl = "http://item.m.jd.com/product/" + trueUrl.Substring(startIndex + 7, lastIndex - startIndex - 7) + ".html";
                    }
                    productUrl = sourceUrl;
                    if (ParamsClass.jdmodel != null)
                    {
                        sourceUrl = GetJDUrl(productUrl);
                    }
                    return sourceUrl;
                }
                else if (trueUrl.Contains("/cps/"))
                {
                    int startIndex = trueUrl.IndexOf("item/");
                    int endIndex = trueUrl.IndexOf("html");
                    string str = "http://item.m.jd.com/product/";
                    if (endIndex > startIndex)
                    {
                        productUrl = str + trueUrl.Substring(startIndex + 5, endIndex - startIndex - 5) + "html";
                        if (ParamsClass.jdmodel != null)
                        {
                            sourceUrl = GetJDUrl(productUrl);
                        }
                        return sourceUrl;
                    }
                }
                else if (trueUrl.Contains("m.jd.com"))
                {


                    //http://c.duomai.com/track.php?site_id=55790&euid=maplefx&t=http://item.m.jd.com/ware/view.action?wareId=1665525
                    //http://item.m.jd.com/ware/view.action?wareId=1759466&sid=179&keyfrom=29520407
                    int firtIndex = trueUrl.LastIndexOf("http");
                    string lastUrl = trueUrl.Substring(firtIndex, trueUrl.Length - firtIndex);
                    int startIndex = trueUrl.IndexOf("product/");
                    int lastIndex = trueUrl.IndexOf(".html");
                    if (lastIndex > startIndex)
                    {
                        sourceUrl = "http://item.m.jd.com/product/" + trueUrl.Substring(startIndex + 8, lastIndex - startIndex - 8) + ".html";
                    }
                    else
                    {
                        //http://item.m.jd.com/ware/view.action?wareId=1759466&sid=179&keyfrom=29520407
                        string strRegex = @"wareId=[1-9]\d*|0$";
                        var numContent = CustomMethod.GetInfoByRegex(strRegex, lastUrl, 0);
                        sourceUrl = "http://item.m.jd.com/product/" + numContent[0].Replace("wareId=", "") + ".html";
                    }
                    productUrl = sourceUrl;
                    if (ParamsClass.jdmodel != null)
                    {
                        sourceUrl = GetJDUrl(productUrl);
                    }
                    return sourceUrl;
                }
                else if (trueUrl.Contains("union.click.jd.com"))
                {
                    productUrl = trueUrl;

                    return "";
                }
                //http://c.duomai.com/track.php?t=http://wqs.jd.com/event/brand/hlqzrn_/index.shtml&aid=61&site_id=94527&euid=n1769696
                else if (trueUrl.Contains("wqs.jd.com"))
                {
                    int startIndex = trueUrl.LastIndexOf("http");
                    productUrl = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                    productUrl = productUrl.Split('&').ToList()[0];
                    sourceUrl = productUrl;
                    return sourceUrl;
                }
                else
                {
                    productUrl = "";
                    return productUrl;
                }
            }
            else if (trueUrl.Contains(".jd.hk"))
            {
                //当静态变量为空时，读取xml数据
                if (ParamsClass.jdmodel == null)
                {
                    ParamsClass.jdmodel = new jdCongfigModel();
                    xmlOperate xmlManager = new xmlOperate();
                    ParamsClass.jdmodel = xmlManager.GetJDModelByXML();
                }
                //http://m.jd.hk/ware/view.action?wareId=1951906523
                //http://c.duomai.com/track.php?k=Ddm0DZpVXZmEjN9QWahZCNwIDO30DZp9VZ0l2cmYiRyUSbvNmLkpmL3d3dGJTJGJTJBNTJwRHdo1&euid=&t=http://item.jd.hk/1951906523.html
                //http://c.duomai.com/track.php?aid=61&site_id=55790&euid=maplefx&t=http://m.jd.hk/ware/view.action?wareId=1952029205
                //http://c.duomai.com/track.php?aid=61&site_id=55790&euid=maplefx&t=http://m.jd.hk/product/1951727187.html
                //sourceUrl = "http://m.jd.hk/ware/view.action?wareId=1951727187";
                //http://m.jd.hk/product/1938564.html&aid=61&site_id=94527&euid=n1815371
                //http://item.jd.hk/1938564.html&aid=61&site_id=94527&euid=n1814908  
                //http://m.jd.hk/product/1931528.html
                //http://item.m.jd.com/product/1931528.html
                //int startIndex = trueUrl.IndexOf("hk/");
                //int endIndex = trueUrl.IndexOf(".html");
                //if (endIndex > startIndex + 3)
                //{
                //    sourceUrl += trueUrl.Substring(startIndex + 3, endIndex - startIndex - 3);
                //}
                //else
                //{
                //    int wareIndex = trueUrl.IndexOf("wareId=");
                //    if (wareIndex > -1)
                //    {
                //        sourceUrl += trueUrl.Substring(wareIndex + 7, trueUrl.Length - wareIndex - 7);
                //    }
                //}
                sourceUrl = "http://item.m.jd.com/product/";
                int startIndex = trueUrl.LastIndexOf("http");
                string currentUrl = trueUrl.Substring(startIndex, trueUrl.Length - startIndex).Split('&').ToList()[0];
                string strRegex = @"hk/[1-9]\d*|0$";
                var numContent = CustomMethod.GetInfoByRegex(strRegex, currentUrl, 0);
                if (numContent.Count > 0)
                {
                    sourceUrl += numContent[0].Replace("hk/", "") + ".html";
                    productUrl = sourceUrl;
                }
                else
                {
                    strRegex = @"wareId=[1-9]\d*|0$";
                    numContent = CustomMethod.GetInfoByRegex(strRegex, currentUrl, 0);
                    if (numContent.Count > 0)
                    {
                        sourceUrl += numContent[0].Replace("wareId=", "") + ".html";
                        productUrl = sourceUrl;
                    }
                }

                if (productUrl != "")
                {
                    if (ParamsClass.jdmodel != null)
                    {
                        sourceUrl = GetJDUrl(productUrl);
                    }
                    return sourceUrl;
                }
                else
                {
                    return "";
                }
            }

        //http://item.yunhou.com/9986001397.html?utm_source=pconline&tk=c0b0BqVOG9
            else if (trueUrl.Contains("yunhou"))
            {
                int startIndex = trueUrl.LastIndexOf("http");
                int endIndex = trueUrl.IndexOf(".html");
                if (endIndex > startIndex)
                {
                    sourceUrl = trueUrl.Substring(startIndex, endIndex - startIndex) + ".html";
                    productUrl = sourceUrl;
                }
                return sourceUrl;
            }
            else if (url.Contains("detail.tmall"))
            {
                if (trueUrl.Contains("&root_refer"))
                {
                    int endIndex = trueUrl.IndexOf("&root_refer");
                    if (endIndex == -1)
                    {
                        endIndex = trueUrl.IndexOf("&ali_trackid");
                    }
                    sourceUrl = trueUrl.Substring(0, endIndex);
                    productUrl = sourceUrl;
                    return sourceUrl;
                }

                //天猫超市 
                if (trueUrl.Contains("chaoshi.detail.tmall") && trueUrl.Contains("&id="))
                {
                    sourceUrl = "https://chaoshi.detail.tmall.com/item.htm?id=";
                    var list = trueUrl.Split('=').ToList();
                    sourceUrl += list[list.Count - 1];
                    productUrl = sourceUrl;
                    return sourceUrl;
                }
                else if (trueUrl.Contains("detail.tmall.hk"))
                {
                    sourceUrl = "https://detail.tmall.hk/hk/item.htm?";
                    var list = trueUrl.Split('&').ToList();
                    if (list.Count > 0)
                    {
                        for (int index = 0; index < list.Count; index++)
                        {
                            if (list[index].Contains("item.htm?id="))
                            {
                                sourceUrl = list[index];
                                break;
                            }
                            else if (list[index].Contains("id="))
                            {
                                int curretindex = list[index].IndexOf("id=");
                                if (curretindex == 0)
                                {
                                    sourceUrl += list[index];
                                    break;
                                }
                            }
                        }
                    }
                    //sourceUrl = list[0];
                    //productUrl = sourceUrl;
                    return sourceUrl;
                }
                else
                {
                    sourceUrl = "https://detail.tmall.com/item.htm?";
                    int startIndex = trueUrl.LastIndexOf("http");
                    string lastStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                    if (startIndex >= 0)
                    {
                        //prepvid=200_10.98.16.176_1815_1446100036445
                        //id=
                        var list = lastStr.Split('&').ToList();
                        if (list.Count > 0)
                        {
                            for (int index = 0; index < list.Count; index++)
                            {
                                if (list[index].Contains("item.htm?id="))
                                {
                                    sourceUrl = list[index];
                                    break;
                                }
                                else if (list[index].Contains("id="))
                                {
                                    int curretindex = list[index].IndexOf("id=");
                                    if (curretindex == 0)
                                    {
                                        sourceUrl += list[index];
                                        break;
                                    }
                                }
                            }
                        }
                        productUrl = sourceUrl;
                        return sourceUrl;
                    }
                    else
                    {
                        var list = trueUrl.Split('&').ToList();
                        if (list.Count > 0)
                        {
                            for (int index = 0; index < list.Count; index++)
                            {
                                if (list[index].Contains("item.htm?id="))
                                {
                                    sourceUrl = list[index];
                                    break;
                                }
                                else if (list[index].Contains("id="))
                                {
                                    int curretindex = list[index].IndexOf("id=");
                                    if (curretindex == 0)
                                    {
                                        sourceUrl += list[index];
                                        break;
                                    }
                                }
                            }
                        }
                        productUrl = sourceUrl;
                        return sourceUrl;
                    }
                }
            }
            else if (url.Contains("detail.ju.taobao.com"))
            {
                //http://detail.ju.taobao.com/home.htm?https://detail.ju.taobao.com/home.htm?item_id=41745267000
                //https://detail.ju.taobao.com/home.htm?spm=a220o.1000855.1998059529.1.JmX01P&item_id=40421441474&ali_trackid=2:mm_29842744_2803335_14720904:1446519925_270_1571437335
                //  string trueUrl = url.Replace("%3A", ":").Replace("%3a", ":").Replace("%2F", "/").Replace("%2f", "/").Replace("%3F", "?").Replace("%3f", "?").Replace("%26", "&").Replace("%3D", "=").Replace("%3d", "=");
                sourceUrl = "https://detail.ju.taobao.com/home.htm?";
                var list = url.Split('&').ToList();
                for (int index = 0; index < list.Count; index++)
                {
                    if (list[index].Contains(".htm?item_id=") || list[index].Contains(".htm?id="))
                    {
                        sourceUrl = list[index];
                        break;
                    }
                    else if (list[index].Contains("item_id="))
                    {
                        sourceUrl += list[index];
                        break;
                    }
                    else if (list[index].Contains("id="))
                    {
                        int curretindex = list[index].IndexOf("id=");
                        if (curretindex == 0)
                        {
                            sourceUrl += list[index];
                            break;
                        }
                    }

                }
                productUrl = sourceUrl;

                return sourceUrl;
            }
            else if (url.Contains("item.taobao.com"))
            {
                sourceUrl = "https://item.taobao.com/item.htm?";
                var list = url.Split('&').ToList();
                if (list.Count > 1)
                {
                    for (int index = 0; index < list.Count; index++)
                    {
                        if (list[index].Contains(".htm?id="))
                        {
                            sourceUrl = list[index];
                            break;
                        }
                        else if (list[index].Contains("id="))
                        {
                            int curretindex = list[index].IndexOf("id=");
                            if (curretindex == 0)
                            {
                                sourceUrl += list[index];
                                break;
                            }
                        }
                        else
                        {
                            sourceUrl = "";
                        }
                    }
                }
                else
                {
                    sourceUrl = trueUrl.Split('?').ToList()[0];
                }
                productUrl = sourceUrl;
                return sourceUrl;
                //}
            }
            else if (trueUrl.Contains("alitrip.com"))
            {
                //阿里旅行
                // https://items.alitrip.com/item.htm?id=521498777962&hlreferid=pctaokedanpin&ali_trackid=2:mm_25282911_3455987_15218806:1446688359_266_1654868761
                sourceUrl = "https://items.alitrip.com/item.htm?";
                var list = url.Split('&').ToList();
                if (list.Count > 1)
                {
                    for (int index = 0; index < list.Count; index++)
                    {
                        if (list[index].Contains(".htm?id="))
                        {
                            sourceUrl = list[index];
                            break;
                        }
                        else if (list[index].Contains("id="))
                        {
                            int curretindex = list[index].IndexOf("id=");
                            if (curretindex == 0)
                            {
                                sourceUrl += list[index];
                                break;
                            }
                            else { continue; }
                        }
                        else
                        {
                            sourceUrl = "";
                        }
                    }

                }
                else
                {
                    sourceUrl = "";
                }
                productUrl = sourceUrl;
                return sourceUrl;
                //}
            }
            else if (trueUrl.Contains("www.tmall.com") && trueUrl.Contains("?"))
            {
                sourceUrl = trueUrl.Split('?').ToList()[0];
                productUrl = sourceUrl;
                return sourceUrl;
            }

       //亚马逊
            else if (trueUrl.Contains("amazon"))
            {
                productUrl = "";
                sourceUrl = "";
                return "";
            }
            //    //http://www.amazon.cn/dpool-é???°????-??·???-????°????é?2è￡?-86005096006-?′?è?2-165/dp/B00GH2U9VA
            //    int zeroIndex = trueUrl.LastIndexOf("http");
            //    trueUrl = trueUrl.Substring(zeroIndex, trueUrl.Length - zeroIndex);
            //    if (trueUrl.Contains("browse") || trueUrl.Contains("/b/") || trueUrl.Contains("/s/") || trueUrl.Contains("/mn/"))
            //    {
            //        productUrl = trueUrl;
            //        return "";
            //    }
            //    else if ((trueUrl.Contains("dp") || url.Contains("gp")))// (url.Contains("?tag") || url.Contains("?t") || url.Contains("?qid") || url.Contains("?psc")))
            //    {
            //        var list = trueUrl.Split('/').ToList();
            //        if (list.Count > 2)
            //        {
            //            sourceUrl = "http://" + list[2] + "/";

           //        }
            //        int startIndex = trueUrl.IndexOf("gp");
            //        if (startIndex == -1)
            //        {
            //            startIndex = trueUrl.IndexOf("dp");
            //        }
            //        int lastIndex = 0;
            //        if (trueUrl.Contains("?"))
            //        {
            //            lastIndex = trueUrl.LastIndexOf("?");
            //            string secondStr = trueUrl.Substring(startIndex, lastIndex - startIndex);

           //            if (secondStr.Contains("ref"))
            //            {
            //                int lastIndex1 = secondStr.IndexOf("ref");
            //                sourceUrl += secondStr.Substring(0, lastIndex1 - 1);
            //                productUrl = sourceUrl;
            //                return sourceUrl;
            //            }
            //        }
            //        else
            //        {
            //            sourceUrl += trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
            //            productUrl = sourceUrl;
            //            return sourceUrl;
            //        }
            //        sourceUrl += trueUrl.Substring(startIndex, lastIndex - startIndex);
            //        productUrl = sourceUrl;
            //        return sourceUrl;
            //    }
            //    else if (trueUrl.Contains("&url="))
            //    {
            //        var list = trueUrl.Split('=').ToList();

           //        sourceUrl = list[list.Count - 1];
            //        productUrl = sourceUrl;
            //        return sourceUrl;
            //    }
            //    else
            //    {
            //        sourceUrl = trueUrl;
            //        productUrl = sourceUrl;
            //        return sourceUrl;
            //    }
            //}
            else if (trueUrl.Contains("yixun.com"))
            {
                if (trueUrl.Contains("item-"))
                {
                    // sourceUrl = "http://item.yixun.com/";
                    sourceUrl = "http://m.yixun.com/t/detail/index.html?pid=";
                    int startIndex = trueUrl.IndexOf("item-");
                    int endIndex = trueUrl.IndexOf(".html");
                    string pid = trueUrl.Substring(startIndex + 5, endIndex - startIndex - 5);

                    // sourceUrl += trueUrl.Substring(startIndex, endIndex - startIndex) + ".html";
                    sourceUrl += pid;
                    productUrl = sourceUrl;
                    return sourceUrl;
                }
                productUrl = trueUrl;
                return "";
            }
            else if (trueUrl.Contains("womai.com"))
            {
                //http://www.womai.com/Product-100-519741.htm
                //http://m.womai.com/0p593554.shtml
                int startIndex = trueUrl.LastIndexOf("http");
                string str = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (str.Contains("?"))
                {
                    sourceUrl = str.Split('?').ToList()[0];
                }
                else
                {
                    sourceUrl = str;
                }
                int mStartIndex = sourceUrl.LastIndexOf("-");
                int mendIndex = sourceUrl.LastIndexOf(".htm");
                if (mendIndex > mStartIndex)
                {
                    string pid = sourceUrl.Substring(mStartIndex + 1, mendIndex - mStartIndex - 1);
                    sourceUrl = "http://m.womai.com/0p" + pid + ".shtml";
                }
                productUrl = sourceUrl;
                return sourceUrl;
            }
            else if (url.Contains("vip.com"))
            {
                string chanel = "http://click.union.vip.com/redirect.php?url=eyJzY2hlbWVjb2RlIjoiMTJjZGEwNDYiLCJ1Y29kZSI6IjljMWY2ZDVjIn0=&desturl=";
                string tag = "&chan=100490";
                int startIndex = trueUrl.LastIndexOf("http");
                sourceUrl = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                productUrl = sourceUrl;
                sourceUrl = sourceUrl.Replace("www.vip.com/detail", "m.vip.com/product");
                //添加渠道号
                string encodUrl = System.Web.HttpUtility.UrlEncode(sourceUrl, System.Text.Encoding.UTF8);
                sourceUrl = chanel + encodUrl + tag;

                return sourceUrl;
            }


            else if (url.Contains("gome"))
            {
                //http://m.gome.com.cn/rushbuy_detail-Q8100651349.html?cmpid=cps_1812_1863_123456&sid=1812&wid=1863&feedback=123456
                // http://m.gome.com.cn/group_buy_detial-T8100665147-0-0.html?cmpid=cps_1812_1863_123456&sid=1812&wid=1863&feedback=123456
                //http://tuan.gome.com.cn/deal/T8100665147.html?cmpid=cps_1812_1863_123456&sid=1812&wid=1863&feedback=123456
                //http://q.gome.com.cn/item/Q8100651349.html?cmpid=cps_1812_1863_123456&sid=1812&wid=1863&feedback=123456 抢购
                string chanel = "?cmpid=cps__22608&sid=&wid=22608";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("http://item.gome.com.cn/"))
                {
                    urlStr = urlStr.Replace("http://item.gome.com.cn/", "http://m.gome.com.cn/product-");
                }
                else if (urlStr.Contains("/tuan.gome.com"))
                {
                    urlStr = urlStr.Replace("http://tuan.gome.com.cn/deal/", "http://m.gome.com.cn/group_buy_detial-");
                    urlStr = urlStr.Replace(".html", "-0-0.html");
                }
                else if (urlStr.Contains("q.gome.com.cn"))
                {
                    urlStr = urlStr.Replace("http://q.gome.com.cn/item/", "http://m.gome.com.cn/rushbuy_detail-");

                }
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else if (urlStr.Contains("&"))
                {
                    sourceUrl = urlStr.Split('&').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }

                productUrl = sourceUrl;
                sourceUrl += chanel;
                return sourceUrl;
            }
            else if (url.Contains("newegg"))
            {
                string chanel = "?cm_mmc=CPS-_-lerdian-_-lerdian-_-11";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else if (urlStr.Contains("&"))
                {
                    sourceUrl = urlStr.Split('&').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                string urlCurrent = sourceUrl.Replace("www", "m");

                productUrl = urlCurrent;

                sourceUrl = urlCurrent + chanel;
                return sourceUrl;
            }
            else if (url.Contains("kaola"))
            {
                string channel = "https://c.duomai.com/track.php?site_id=227958&aid=1737&euid=maytao&t=";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else if (urlStr.Contains("&"))
                {
                    sourceUrl = urlStr.Split('&').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                if (sourceUrl.Contains("product"))
                {
                    productUrl = sourceUrl.Replace("www", "m");
                }
                sourceUrl = channel + System.Web.HttpUtility.UrlEncode(productUrl, System.Text.Encoding.UTF8); ;
                return sourceUrl;
            }
            else if (trueUrl.Contains("lifevc.com"))
            {
                //http://www.lifevc.com/item/12217
                string newUrl = "http://m.lifevc.com/h5/#/item/";
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else if (urlStr.Contains("&"))
                {
                    sourceUrl = urlStr.Split('&').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                if (sourceUrl.Contains("item"))
                {
                    string strRegex = @"item/[1-9]\d*|0$";
                    var numContent = CustomMethod.GetInfoByRegex(strRegex, sourceUrl, 0);
                    if (numContent.Count > 0)
                    {
                        newUrl += numContent[0].Replace("item/", "");
                    }
                    else
                    {
                        newUrl = sourceUrl;
                    }
                }
                else
                {
                    newUrl = sourceUrl;
                }
                productUrl = sourceUrl;
                return newUrl;
            }

        //海购
            else if (url.Contains("rei.com") || url.Contains("zm7.cn")
                || url.Contains("disneystore") || url.Contains("maycys") || url.Contains("ehaier")
             || url.Contains("woot.com") || trueUrl.Contains("shopbop.com"))
            {
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else if (urlStr.Contains("&"))
                {
                    sourceUrl = urlStr.Split('&').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                productUrl = sourceUrl;
                return sourceUrl;
            }
            else if (trueUrl.Contains("thewatchery"))
            {
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                productUrl = urlStr;
                return urlStr;
            }

            if (url.Contains(UrlType.nuomi.ToString())
               || url.Contains(UrlType.showjoy.ToString())
                || url.Contains("feiniu.com") || url.Contains("ebay.com")
                || url.Contains("dapu.com") || url.Contains("supuy.com") || url.Contains("ashford") || url.Contains("lamahui.com")
                || (url.Contains("aidai.com")) || url.Contains("sierratradingpost") || url.Contains("strawberrynet") || url.Contains("fredericks.com")
                || url.Contains("mybag.com") || url.Contains("boqii.com") || url.Contains("microsoftstore.com") || url.Contains("homevv.com")
                || url.Contains("saksoff5th.com") || url.Contains("hqhair.com") || trueUrl.Contains("mankind.co.uk")
                || url.Contains("hitao.com") || url.Contains("backcountry") || url.Contains("hangowa.com") || url.Contains("eastbay.com") || url.Contains("joesnewbalanceoutlet")
                || url.Contains("banggo.com") || url.Contains("lastcall.com") || url.Contains("kidsroom") || url.Contains("tiantian") || url.Contains("mei.com")
                || url.Contains("bluefly") || url.Contains("allsole.com") || url.Contains("jomadeals.com") || url.Contains("gilt.com") || url.Contains("myhabit.com")
                || url.Contains("jomashop.com") || url.Contains("finishline") || url.Contains("joesnewbalanceoutlet") || url.Contains("zatchels") || url.Contains("bhphotovideo")
                || url.Contains("victoriassecret") || url.Contains("shopin.net") || url.Contains("lookfantastic.com") || url.Contains("moosejaw.com")
                || trueUrl.Contains("100yue") || trueUrl.Contains("usa.canon.com") || trueUrl.Contains("oshkosh") || trueUrl.Contains("iherb.com")
                || trueUrl.Contains("okhqb.com") || trueUrl.Contains("dolce-gusto.hk") || trueUrl.Contains("ruelala.com") || trueUrl.Contains("dolce-gusto.hk") || trueUrl.Contains("ule.com")
                || trueUrl.Contains("zhongmian.com") || trueUrl.Contains("walmart.com") || trueUrl.Contains("quwan.com") || trueUrl.Contains("endclothing.com") || trueUrl.Contains("worldofwatches")
                || trueUrl.Contains("vitacost") || trueUrl.Contains("follifollie") || trueUrl.Contains("gou.com") || trueUrl.Contains("chemistdirect") || trueUrl.Contains("vancl.com"))
            {
                int startIndex = trueUrl.LastIndexOf("http");
                string urlStr = trueUrl.Substring(startIndex, trueUrl.Length - startIndex);
                if (urlStr.Contains("?"))
                {
                    sourceUrl = urlStr.Split('?').ToList()[0];
                }
                else
                {
                    sourceUrl = urlStr;
                }
                productUrl = sourceUrl;
                return sourceUrl;
            }

            else if (url.Contains(UrlType.okbuy.ToString()))
            {
                //http://www.okbuy.com/p-toread/detail-shoe-17173408.html
                var list = trueUrl.Split('?').ToList();
                sourceUrl = list[0].Replace("www", "t");
                productUrl = list[0];
                return sourceUrl;
            }
            else
            {
                // CustomMethod.WriteLog(trueUrl);
                //if (trueUrl.Contains("taobao"))
                //{
                productUrl = trueUrl;
                return "";
                //}
                //productUrl = trueUrl;
                //sourceUrl = productUrl;
                //return sourceUrl;
            }
        }
        /// <summary>
        /// 获取枚举类子项描述信息
        /// </summary>
        /// <param name="enumSubitem">枚举类子项</param>        
        public static string GetEnumDescription(object enumSubitem)
        {
            enumSubitem = (Enum)enumSubitem;
            string strValue = enumSubitem.ToString();

            FieldInfo fieldinfo = enumSubitem.GetType().GetField(strValue);

            if (fieldinfo != null)
            {
                Object[] objs = fieldinfo.GetCustomAttributes(typeof(DescriptionAttribute), false);

                if (objs == null || objs.Length == 0)
                {
                    return strValue;
                }
                else
                {
                    DescriptionAttribute da = (DescriptionAttribute)objs[0];
                    return da.Description;
                }
            }

            return "";
        }
        /// <summary>
        /// 根据渠道号 好url 生成推广链接
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        private static string GetUrlByChannel(string channel, string url)
        {
            string encodUrl = System.Web.HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8);
            string sourceUrl = channel + encodUrl;
            return sourceUrl;
        }

        /// <summary>
        /// 根据解析出的京东url生成推广url
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private static string GetJDUrl(string url)
        {
            try
            {
                string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                //拼接https请求获取推广链接
                string getUrl = @"https://api.jd.com/routerjson?v=2.0&method=jingdong.service.promotion.app.getcode&app_key=" + ParamsClass.jdmodel.appkey + "&access_token=" + ParamsClass.jdmodel.access_token + "&360buy_param_json={\"jdurl\": \"" + url + "\",\"appId\":\"" + ParamsClass.jdmodel.appid + "\",\"subUnionId\":\"\",\"positionId\":\"\",\"ext\":\"\"}&timestamp=" + time + "";
                string txt = CustomMethod.GetHtmlByHttpHelper(getUrl);
                int startIndex = txt.IndexOf("http");
                int endIndex = txt.LastIndexOf(@"\");
                if (startIndex > 0 && endIndex > startIndex)
                {
                    return txt.Substring(startIndex, endIndex - startIndex);
                }
                else
                {
                    return url;
                }
            }
            catch (Exception ex)
            {
                CustomMethod.WriteLog("GetJDUrl:" + ex.Message.ToString());
                return url;
            }
        }
    }


    //#region 各网站渠道号对象实例
    //public class DangDang
    //{
    //    private string name = "dangdang";
    //    private string chanel = "?unionid=p-327780m";
    //    public string Name
    //    {
    //        set { name = value; }
    //        get { return name; }
    //    }
    //    public string Chanel
    //    {
    //        set { chanel = value; }
    //        get { return chanel; }
    //    }
    //}
    ////   public class 

    //#endregion
}
